<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<%@include file="/WEB-INF/views/common/header.jsp" %>
	<title>创建管理员</title>
</head>
<body>
<%@include file="/WEB-INF/views/common/top.jsp" %>
<%@include file="/WEB-INF/views/common/nav.jsp" %>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
	<div class="show-top-grids">
		<div class="main-grids about-main-grids">
			<h4>修改密码</h4>
			<div class="recommended-info" pane="">

				<hr class="layui-bg-green">
				<form id="editPasswordForm" class="layui-form layui-form-pane" style="margin-top: 1em;" method="post"
				      action='<c:url value="/master/update"/>'>
					<div class="layui-row">
						<div class="layui-inline">
							<label class="layui-form-label">旧密码</label>
							<div class="layui-input-inline">
								<input type="password" name="oldPassword"  id="oldPassword" placeholder="旧密码" autocomplete="off" class="layui-input"/>
							</div>
						</div>
					</div>
					<div class="layui-row">
						<div class="layui-inline">
							<label class="layui-form-label">新密码</label>
							<div class="layui-input-inline">
								<input type="password" name="password"  id="newPassword" placeholder="新密码" autocomplete="off" class="layui-input"/>
							</div>
						</div>
					</div>
					<div class="layui-row">
						<div class="layui-inline">
							<label class="layui-form-label">旧密码</label>
							<div class="layui-input-inline">
								<input type="password" name="confirmPassword"  id="confirmPassword" placeholder="确认密码" autocomplete="off" class="layui-input"/>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-inline">
							<button class="layui-btn" type="submit">修改密码</button>
						</div>
					</div>

				</form>
			</div>
		</div>
	</div>

</div>
</body>

<script type="application/javascript">

	/*导航栏参数*/
    var $nav_a = $("#ul_nav a[href='/master/editPassword']");
	$nav_a.parent().addClass("active");
	$nav_a.parent().parent().css("display", "block");

	layui.use('layer', function () {
		 window.layer = layui.layer;
	});

	/*验证信息*/
	window.fault = false;
	$("#editPasswordForm").validate({
		onfocusout: false,
		onkeyup: false,
		onclick: false,
		submitHandler: function () {
			var formData = $('#editPasswordForm').serializeObject();
			var password = formData["password"] || '';
			var oldPassword = formData["oldPassword"] || '';
			formData["password"] = $.md5(password);
			formData["oldPassword"] = $.md5(oldPassword);
			formData = JSON.stringify(formData);
			$.ajax({
				url: '<c:url value="/master/updatePassword"/>',
				dataType: 'json',
				type: 'post',
				data: formData,
				contentType: "application/json",
				error: function () {
				},
				success: function (data) {
					if (data.code !== "200") {
						window.layer.msg(data.message, {icon: 5, anim: 6});
					} else {
						window.location.href = '<c:url value="/master/list"/>';
					}
				}
			});
		},
		rules: {
			oldPassword: {
				required: true,
				minlength: 6
			}
			,password: {
				required: true,
				minlength: 6
			}
			, confirmPassword: {
				required: true,
				minlength: 6,
				validPassword: "newPassword"
			}
		},
		messages: {
			newPassword: {
				required: "请输入原密码",
				minlength: "原密码长度不能小于 6 个字母"
			}
			,password: {
				required: "请输入新密码",
				minlength: "新密码长度不能小于 6 个字母"
			}
			, confirmPassword: {
				required: "请再次输入密码",
				minlength: "确认密码长度不能小于 6 个字母",
				validPassword: "两次密码不一致"
			}
		},
		showErrors: function (errorMap, errorList) {
			window.fault = this.numberOfInvalids() > 0;
			this.defaultShowErrors();
		},
		errorPlacement: function (error, element) {
			if (window.fault) {
				window.fault = false;
				$(element).addClass("layui-form-danger").focus();
				window.layer.msg($(error).text(), {icon: 5, anim: 6});
			}
		}
	});

</script>


</html>
